﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="OrdersControl.ascx.cs" Inherits="Controls_OrdersControl" %>

<%@ Register Src="~/Controls/DayStatisticControl.ascx" TagPrefix="uc" TagName="day" %>
<%@ Register Src="~/Controls/FamilyCalendar.ascx" TagPrefix="uc" TagName="calendar" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<script type="text/javascript">

    function setCaret(id) {
        var input = $get(id);
        if (input.setSelectionRange) {
            // Other
            input.focus();
            input.setSelectionRange(input.value.length, input.value.length);
        }
        else if (input.createTextRange) {
            // IE
            var range = input.createTextRange();
            range.collapse(true);
            range.moveEnd('character', input.value.length);
            range.moveStart('character', input.value.length);
            range.select();
        }
    }

    function validateKey(e) {
        return (e.keyCode > 34 || e.keyCode == 8) ;
    }

    function onKeyUp(e, id) {
        if (validateKey(e)) __doPostBack(id.toString(), '');
    }

</script>

<table width="100%">
    <tr>
        <td colspan="3">
            <asp:Calendar ID="mainCalendar" runat="server" BackColor="#FFFFCC" 
                BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest" 
                Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
                ondayrender="mainCalendar_DayRender" Width="710px" ShowGridLines="True" 
                onselectionchanged="mainCalendar_SelectionChanged">
                <DayHeaderStyle BackColor="#FFCC66" Height="1px" Font-Bold="True" />
                <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
                <OtherMonthDayStyle ForeColor="#CC9966" />
                <SelectedDayStyle BackColor="#CCCCFF" ForeColor="Black" Font-Bold="True" />
                <SelectorStyle BackColor="#FFCC66" />
                <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
                <TodayDayStyle BackColor="#FFCC66" ForeColor="Blue" />
            </asp:Calendar>
        </td>
    </tr>
    <tr>
        <td>
            Введите сумму: <asp:TextBox ID="txtAmount" runat="server" Enabled="false" Width="50px" />
            
            <asp:RequiredFieldValidator ID="amountError2" runat="server" ErrorMessage="*" ValidationGroup="Order"
                ControlToValidate="txtAmount" ToolTip="Введите сумму!" />

            <asp:RegularExpressionValidator ID="amountError" runat="server" ErrorMessage="*" ToolTip="Сумма в неверном формате!"
                Display="None" ControlToValidate="txtAmount" ValidationExpression="[0-9]*,?[0-9]*" ValidationGroup="Order" />

        </td>
        <td align="center">
            <asp:Label ID="lblProductName" runat="server" ForeColor="Red" />
        </td>
        <td align="right">
            <asp:Button ID="btnAdd" runat="server" Text="Добавить" Enabled="false" 
                onclick="btnAdd_Click" ValidationGroup="Order" />
        </td>
    </tr>
    <tr>
        <td colspan="3">
            <table width="100%">
                <tr>
                    <td style="vertical-align: top;">
            <asp:ListView ID="lvCategories" runat="server" DataKeyNames="Id" 
                oniteminserting="lvCategories_ItemInserting" 
                onselectedindexchanging="lvCategories_SelectedIndexChanging" 
                InsertItemPosition="FirstItem" onitemdatabound="lvCategories_ItemDataBound"
                OnItemCanceling="lvCategories_Canceling"
                OnItemDeleting="lvCategories_Deleting"
                OnItemEditing="lvCategories_Editing"
                OnItemUpdating="lvCategories_Updating">
                <LayoutTemplate>
                    <table class="list">
                        <thead>
                            <tr style="height: 30px;">
                                <td style="width: 75%;">Имя</td>
                                <td style="width: 25%;">Действия</td>
                            </tr>
                        </thead>
                        <tr id="itemPlaceholder" runat="server" />
                    </table>
                </LayoutTemplate>

                <ItemTemplate>
                    <tr id="tr" runat="server" class='<%# Container.DataItemIndex % 2 == 0 ? "listRow" : "altListRow" %>'>
                        <td>
                            <%# Eval("Name") %>
                        </td>
                        <td>
                            <asp:ImageButton ID="btnSelect" runat="server" CommandName="Select" ImageUrl="~/Images/icons/Warning.png"
                                ToolTip="Выбрать" Width="16px" Height="16px" />&nbsp;
                            <asp:ImageButton ID="btnEdit" runat="server" CommandName="Edit" ImageUrl="~/Images/icons/Edit.png" ToolTip="Редактировать"
                                 Width="16px" Height="16px" />&nbsp;
                            <asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" ImageUrl="~/Images/icons/Delete.png" ToolTip="Удалить"
                                 Width="16px" Height="16px" OnClientClick="return confirm('Вы уверены, что хотите удалить эту категорию???');" />
                        </td>
                    </tr>
                </ItemTemplate>

                <EditItemTemplate>
                    <tr id="tr" runat="server" class='<%# Container.DataItemIndex % 2 == 0 ? "listRow" : "altListRow" %>'>
                        <td>
                            <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>' ValidationGroup="category" />
                            <asp:RequiredFieldValidator ID="eNameReq" runat="server" ErrorMessage="*" ForeColor="Red"
                                ControlToValidate="txtName" ValidationGroup="category" />
                        </td>
                        <td>
                            <asp:ImageButton ID="btnCancel" runat="server" CommandName="Cancel" ImageUrl="~/Images/icons/Cancel.png"
                                ToolTip="Отменить" Width="16px" Height="16px" />&nbsp;
                            <asp:ImageButton ID="btnApply" runat="server" CommandName="Update" ImageUrl="~/Images/icons/Apply.png" ToolTip="Применить"
                                 Width="16px" Height="16px" ValidationGroup="category" />
                        </td>
                    </tr>
                </EditItemTemplate>

                <InsertItemTemplate>
                    <tr class="insertRow">
                        <td>
                            <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>' />

                            <asp:RequiredFieldValidator ID="nameError" runat="server" ToolTip="Введите имя категории!"
                                ValidationGroup="categoryInsert" ControlToValidate="txtName" ErrorMessage="*" />
                        </td>
                        <td>
                            <asp:ImageButton ID="btnInsert" runat="server" CommandName="Insert" ImageUrl="~/Images/icons/Add.png" 
                                ValidationGroup="categoryInsert" ToolTip="Добавить" Width="16px" Height="16px" />
                        </td>
                    </tr>
                </InsertItemTemplate>

                <SelectedItemTemplate>
                    <tr class="selectedRow">
                        <td colspan="2">
                            <%# Eval("Name") %>
                        </td>
                    </tr>
                </SelectedItemTemplate>

            </asp:ListView>
        </td>
        <td style="vertical-align: top;">
            <asp:ListView ID="lvProducts" runat="server" DataKeyNames="Id" 
                oniteminserting="lvProducts_ItemInserting" 
                onselectedindexchanging="lvProducts_SelectedIndexChanging" 
                OnItemDataBound="lvProducts_ItemDataBound"
                InsertItemPosition="FirstItem"
                OnItemCanceling="lvProducts_Canceling" 
                OnItemDeleting="lvProducts_Deleting" 
                OnItemEditing="lvProducts_Editing" 
                OnItemUpdating="lvProducts_Updating">
                <LayoutTemplate>
                    <table class="list">
                        <thead>
                            <%--<tr>
                                <td colspan="2">
                                    <asp:DataPager ID="pager" runat="server" PageSize="10" >
                                        <Fields>
                                            <asp:NumericPagerField ButtonCount="10" />
                                            <asp:NextPreviousPagerField 
                                                FirstPageImageUrl="~/Images/icons/First.png" 
                                                LastPageImageUrl="~/Images/icons/Last.png"
                                                NextPageImageUrl="~/Images/icons/Next.png"
                                                PreviousPageImageUrl="~/Images/icons/Previous.png" 
                                                ShowFirstPageButton="true" ShowLastPageButton="true" ButtonType="Image" />
                                        </Fields>
                                    </asp:DataPager>
                                </td>
                            </tr>--%>
                            <tr style="height: 30px;">
                                <td style="width: 75%;">Имя<asp:TextBox ID="txtProductName" runat="server" Width="50px" OnTextChanged="txtProductName_Changed" AutoPostBack="true" /></td>
                                <td style="width: 25%;">Действия</td>
                            </tr>
                        </thead>
                        <tr id="itemPlaceholder" runat="server" />
                    </table>
                </LayoutTemplate>

                <ItemTemplate>
                    <tr id="tr" runat="server" class='<%# Container.DataItemIndex % 2 == 0 ? "listRow" : "altListRow" %>'>
                        <td>
                            <%# Eval("Name") %>
                        </td>
                        <td>
                            <asp:ImageButton ID="btnSelect" runat="server" CommandName="Select" ImageUrl="~/Images/icons/Warning.png"
                                ToolTip="Выбрать" Width="16px" Height="16px" />&nbsp;
                            <asp:ImageButton ID="btnEdit" runat="server" CommandName="Edit" ImageUrl="~/Images/icons/Edit.png" ToolTip="Редактировать"
                                 Width="16px" Height="16px" />&nbsp;
                            <asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" ImageUrl="~/Images/icons/Delete.png" ToolTip="Удалить"
                                 Width="16px" Height="16px" OnClientClick="return confirm('Вы уверены, что хотите удалить этот продукт???');" />
                        </td>
                    </tr>
                </ItemTemplate>

                <EditItemTemplate>
                    <tr id="tr" runat="server" class='<%# Container.DataItemIndex % 2 == 0 ? "listRow" : "altListRow" %>'>
                        <td>
                            <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>' />
                            <asp:RequiredFieldValidator ID="eNameReq" runat="server" ErrorMessage="*" ForeColor="Red"
                                ControlToValidate="txtName" ValidationGroup="product" />
                        </td>
                        <td>
                            <asp:ImageButton ID="btnCancel" runat="server" CommandName="Cancel" ImageUrl="~/Images/icons/Cancel.png"
                                ToolTip="Отемнить" Width="16px" Height="16px" />&nbsp;
                            <asp:ImageButton ID="btnApply" runat="server" CommandName="Update" ImageUrl="~/Images/icons/Apply.png" ToolTip="Применить"
                                 Width="16px" Height="16px" ValidationGroup="product" />
                        </td>
                    </tr>
                </EditItemTemplate>

                <InsertItemTemplate>
                    <tr class="insertRow">
                        <td>
                            <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>' />

                            <asp:RequiredFieldValidator ID="nameError" runat="server" ErrorMessage="*"
                                ValidationGroup="productInsert" ControlToValidate="txtName" ToolTip="Введите имя продукта!" />
                        </td>
                        <td>
                            <asp:ImageButton ID="btnInsert" runat="server" CommandName="Insert" ImageUrl="~/Images/icons/Add.png" 
                                ValidationGroup="productInsert" ToolTip="Добавить" Width="16px" Height="16px" />
                        </td>
                    </tr>
                </InsertItemTemplate>

                <SelectedItemTemplate>
                    <tr class="selectedRow">
                        <td colspan="2">
                            <%# Eval("Name") %>
                        </td>
                    </tr>
                </SelectedItemTemplate>

            </asp:ListView>
        </td>
                </tr>
            </table>
        </td>
        
    </tr>
    <tr>
        <td colspan="3">
            <uc:day ID="day" runat="server" />
        </td>
    </tr>
</table>